﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DownloadDetails : Acms.AcmsControls.ContentControls.Admin.BaseCustomAdminControl
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        grid.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(grid_NeedDataSource);
    }

    void grid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        ClimateChangeChampionsData.DataContext context = new ClimateChangeChampionsData.DataContext();

        var data = from download in context.Downloads
                   join user in context.Users on download.UserId equals user.Id
                   join schoolName in context.UserCustomProperties on user.Id equals schoolName.UserId into sn
                   from schoolName in sn.DefaultIfEmpty()
                   where download.Name == Request.QueryString["Id"] && schoolName.Name == "School Name"
                   orderby download.Created descending
                   select new
                   {
                       Date = download.Created,
                       UserName = user.UserName,
                       Email = user.EmailAddress,
                       School = schoolName != null ? schoolName.Value : null
                   };

        grid.DataSource = data;
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }


}
